﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Lm.Common.ExtensionMethods;

namespace Lm.Common.Auth.Account
{
    public class AccountDal
    {
        public Model.Account GetByUserAccount(string userAccount)
        {
            if (userAccount.IsNullOrBlank())
            { throw new Exception("必须输入帐号"); }
            using (var tran = new System.Transactions.TransactionScope())
            {
                var helper = DAL.DALFactory.Create();
                if (helper.IsSingle<Model.Account>(t => t.UserAccount == userAccount) == false)
                { throw new Exception("帐号不存在"); }
                var account = helper.GetSingle<Model.Account>(t => t.UserAccount == userAccount);
                tran.Complete();
                return account;
            }
        }

        public Model.Account GetByUserId(Guid userId)
        {           
            using (var tran = new System.Transactions.TransactionScope())
            {
                var helper = DAL.DALFactory.Create();
                var account = helper.GetSingle<Model.Account>(t => t.Id == userId);
                tran.Complete();
                return account;
            }
        }
    }
}
